package com.diudiutechnology.www.yadiudiu.yadiudiu.car.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.util.http.User;
import com.diudiutechnology.www.yadiudiu.util.utils.RatingBar;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.BuyACarFragmentModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/2.
 * 购车
 */

public class BuyACarDoorFragmentAdapter extends BaseAdapter {

    private Context mContext;
    ArrayList<User.DataBean.StrokeList> toolList;
    BuyACarDoorFragmentAdapter.ViewHolder holder=null;
//    List<BuyACarFragmentModel> model= new ArrayList<>();
    public BuyACarDoorFragmentAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return toolList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
//    public void addItem( List<BuyACarFragmentModel> model){
//
//        this.model=model;
//        notifyDataSetChanged();
//    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_cleaning, null);
            holder.item_image = (ImageView) convertView
                    .findViewById(R.id.item_image);
            holder.item_title = (TextView) convertView
                    .findViewById(R.id.item_title);
            holder.rating = (RatingBar) convertView
                    .findViewById(R.id.rating);
            holder.item_content = (TextView) convertView
                    .findViewById(R.id.item_content);
            holder.positioning_text = (TextView) convertView
                    .findViewById(R.id.positioning_text);
            holder.browse_text = (TextView) convertView
                    .findViewById(R.id.browse_text);
            holder.comments_text = (TextView) convertView
                    .findViewById(R.id.comments_text);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position==0){
            holder.item_image.setImageResource(R.mipmap.imwash_the_car1);
        }else if (position==1){
            holder.item_image.setImageResource(R.mipmap.imwash_the_car2);
        }else {
            holder.item_image.setImageResource(R.mipmap.imwash_the_car3);
        }


//        BuyACarFragmentModel bModel = model.get(position);
        holder.item_title.setText(toolList.get(position).name);
        holder.item_content.setText(toolList.get(position).brand);
        holder.positioning_text.setText(toolList.get(position).km+"km");
        holder.browse_text.setText(toolList.get(position).thenumberof);
        holder.comments_text.setText(toolList.get(position).countcomment);

        holder.rating.setClickable(false);//设置可否点击
        holder.rating.setStar(toolList.get(position).star);//设置显示的星星个数
        return convertView;
    }

    class ViewHolder {
        ImageView item_image;
        TextView item_title;
        RatingBar rating;

        TextView item_content;

        TextView positioning_text;
        TextView browse_text;
        TextView comments_text;

    }
}

